CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

FUNCTION(SET_TARGET_INCLUDE TARGET_NAME INCLUDE_DIRECTORY)

    IF ( NOT TARGET ${TARGET_NAME} )
        MESSAGE ( FATAL_ERROR "SET_TARGET_INCLUDE::Target ${TARGET_NAME} does not exist!" )
    ENDIF()

    IF ( NOT EXISTS ${INCLUDE_DIRECTORY} )
        MESSAGE ( WARNING "SET_TARGET_INCLUDE::Include directory to be set for ${TARGET_NAME} does not exist!" )
    ENDIF()

    IF ( ${CMAKE_VERSION} VERSION_GREATER "2.8.9" )
        GET_PROPERTY ( INC_DIR TARGET ${TARGET_NAME}  PROPERTY INCLUDE_DIRECTORIES )
        SET ( INC_DIR "${INC_DIR};${INCLUDE_DIRECTORY}" ) 
        SET_PROPERTY ( TARGET ${TARGET_NAME} PROPERTY INCLUDE_DIRECTORIES "${INC_DIR}" )
    ELSE ()
    
        SET ( INCLUDE_PREFIX "-I" )
        IF ( MSVC )
            SET ( INCLUDE_PREFIX "/I" )
        ENDIF()

        GET_PROPERTY ( COMP_FLAGS TARGET ${TARGET_NAME} PROPERTY COMPILE_FLAGS)
        SET(COMP_FLAGS "${COMP_FLAGS} ${INCLUDE_PREFIX}${INCLUDE_DIRECTORY} ")
        SET_TARGET_PROPERTIES (${TARGET_NAME} PROPERTIES COMPILE_FLAGS ${COMP_FLAGS})
    ENDIF()

ENDFUNCTION(SET_TARGET_INCLUDE TARGET_NAME INCLUDE_DIRECTORY)
